var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var indexRouter = require('./routes/index');

var app = express();


app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);

//错误处理中间件
app.use((err,req,res,next)=>{
  //查看得到错误
  console.log(err);
  //响应500
  res.status(500).send({code: 500,msg: '服务器端错误'});
});

module.exports = app;
